package com.orangelife.mobile.tehui;

import android.os.Handler;
import android.text.TextUtils;

import com.curry.android.http.HttpUtil;
import com.curry.android.http.OrangeDataHandler;
import com.curry.android.http.OrangeErrorHandler;
import com.curry.android.http.VolleyHttpUtil;
import com.orangelife.mobile.common.biz.JSONRequest;
import com.common.sp.UserSp;
import com.orangelife.mobile.constants.Constant;
import com.orangelife.mobile.constants.TeHuiURL;
import com.orangelife.mobile.util.TimeUtil;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by YangWei
 * on 2016/4/5.
 */
public class TeHuiBiz {

    public static final int POST_REMIND = 302;
    public static final int GET_TEHUI_DETAIL = 303;

    /**
     * 活动明细
     */
    public static void getTehuiData(String activityID, VolleyHttpUtil.ResponseCallBack callback) {
        //如果只传小区id，返回该小区当前活动。如果传小区id和当前活动id则返回预热的活动
        HashMap<String, String> urlMap = new HashMap<>();
        if (!TextUtils.isEmpty(activityID)) {
            urlMap.put("activityID", activityID);
        }
        VolleyHttpUtil.getInstance().getWithCallback(TeHuiURL.TEHUI_LIST, urlMap, callback);
    }

    /**
     * 活动商品详情
     */
    public static void getTehuiDataDetail(String activityGoodsID, Handler handler) {
        //如果只传小区id，返回该小区当前活动。如果传小区id和当前活动id则返回预热的活动
        HashMap<String, String> map = new HashMap<>();
        map.put("activityGoodsID", activityGoodsID);
//        Map<String, Object> rootMap = new HashMap<>();
//        rootMap.put("map", map);
//        rootMap.put("url", Constant.URL_TEHUI_DETAIL); // /activityGoodDetailApp
//        rootMap.put("wat", GET_TEHUI_DETAIL);
//        JSONRequest.getInstance().sendRequest(JSONRequest.GET, rootMap, handler,
//                HttpUtil.ACTION_URI);
        VolleyHttpUtil.getInstance().getWithHandler(Constant.URL_TEHUI_DETAIL,handler,GET_TEHUI_DETAIL,map);
    }

    /**
     * 活动开抢提醒
     * activityGoodsID 活动商品id
     */
    public static void getRemindInfo(String activityID, VolleyHttpUtil.ResponseCallBack callback) {
        HashMap<String, String> urlMap = new HashMap<>();
        urlMap.put("activityID", activityID);
        VolleyHttpUtil.getInstance().getWithCallback(TeHuiURL.TEHUI_REMIND, urlMap, callback);
    }


    /**
     * 解析数据
     *
     * @param response
     * @return
     */
    public static Map<String, Object> parseJson(Object response) {
        if (OrangeErrorHandler.getInstance().isSuccess(response)) {
            if (response instanceof JSONObject) {
                Map<String, Object> map = OrangeDataHandler.getMapWithEntity((JSONObject) response);
                return map;
            }
        }
        return null;
    }


}
